package cn.tsvtc.springboot.controller;/**
 * @Author Athena
 * @Date 2020/10/23 16:18
 * @Version 1.0
 * @Description no description
 */

import cn.tsvtc.springboot.entity.Category;
import cn.tsvtc.springboot.entity.Goods;
import cn.tsvtc.springboot.entity.GoodsTemple;
import cn.tsvtc.springboot.service.GoodsService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Athena
 * @date: 2020/10/23 16:18
 * @description:
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @PostMapping("/add")
    public String add(@RequestBody Goods goods){
        GoodsTemple goodsTemple = new GoodsTemple();
        goodsTemple.setCid(goods.getCid());
        goodsTemple.setId(goods.getId());
        goodsTemple.setGoodsDesc(goods.getGoodsDesc());
        goodsTemple.setGoodsName(goods.getGoodsName());
        goodsTemple.setId(goods.getId());

        int insert = goodsService.insert(goodsTemple);
        return new String("添加了"+String.valueOf(insert));
    }

    @RequestMapping("/getAll")
    public String getAll(){
        List<GoodsTemple> all = goodsService.getAll();
        String jsonString = JSON.toJSONString(all);
        return jsonString;
    }
}
